package oocl.eshop.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oocl.eshop.po.Merchant;
import oocl.eshop.service.MerchantManager;
import oocl.eshop.service.impl.MerchantManagerImpl;

/**
 * Servlet implementation class Refresh
 */
public class Refresh extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MerchantManager mer = new MerchantManagerImpl();
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Refresh() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession sen=request.getSession();
		
		List<Merchant> mers=mer.findAllMerchant();
		int size=mers.size();
		int pageSize=(int)sen.getAttribute("pageSize");
		int pageSum=(size%pageSize==0)?(size/pageSize):(size/pageSize+1);
		sen.setAttribute("size", size);
		sen.setAttribute("pageSum", pageSum);
		sen.setAttribute("curPage", 1);
		sen.setAttribute("pageSize", pageSize);
		
		
		
		
		sen.setAttribute("mers", mers);
		request.getRequestDispatcher("merManage.jsp").forward(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
	
	

}
